package com.ant.cn.duomen01;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import java.util.List;
import java.util.Map;

public class OfferListAdapter extends BaseAdapter {

	private List<Map<String, Object>> aowList;
	private LayoutInflater inflater;

	public OfferListAdapter(Context context,
			List<Map<String, Object>> aowObjects) {
		this.aowList = aowObjects;
		this.inflater = LayoutInflater.from(context);
	}

	@Override
	public int getCount() {
		return aowList.size();
	}

	@Override
	public Object getItem(int position) {
		return aowList.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder viewHolder;
		if (convertView == null) {
			viewHolder = new ViewHolder();
			convertView = this.inflater.inflate(R.layout.dm_item_list_offer, null);
			viewHolder.tv_appName = (TextView) convertView
					.findViewById(R.id.dm_item_list_offer_tv_name);
			viewHolder.tv_appSize = (TextView) convertView
					.findViewById(R.id.dm_item_list_offer_tv_size);
			viewHolder.tv_taskContent = (TextView) convertView
					.findViewById(R.id.dm_item_list_offer_tv_content);
			viewHolder.tv_points = (TextView) convertView
					.findViewById(R.id.dm_item_list_offer_tv_point);
			convertView.setTag(viewHolder);
		} else {
			viewHolder = (ViewHolder) convertView.getTag();
		}

		Map<String, Object> obj = aowList.get(position);
		// 任务名称
		viewHolder.tv_appName.setText(obj.get("name").toString());
		// 任务下载应用的大小
		viewHolder.tv_appSize.setText(obj.get("size").toString());
		// 任务简短描述
		viewHolder.tv_taskContent.setText(obj.get("brife_desc").toString());
		// 任务奖励的积分
		viewHolder.tv_points.setText(obj.get("point").toString());
		return convertView;
	}

	public class ViewHolder {
		public TextView tv_appName;
		public TextView tv_appSize;
		public TextView tv_taskContent;
		public TextView tv_points;
	}

}
